package com.yellowpage.bigdata.action;
  
import com.yellowpage.bigdata.data.NspOnofflogTaImeiDayEntity;
import com.yellowpage.bigdata.service.NspOnofflogTaImeiDayEntityService;
import com.yellowpage.tool.Excelexport;
import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.struts.BaseAction;

import java.util.*;

public class NspOnofflogTaImeiDayEntityAction extends BaseAction {

    public String RESULT_QUERY = "query";
    public String RESULT_ADD = "add";
	public String RESULT_EDIT = "edit";
	
	private Configuration configuration;

	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}
	
	private List<NspOnofflogTaImeiDayEntity> nspOnofflogTaImeiDayEntityList = new ArrayList<NspOnofflogTaImeiDayEntity>();
	private List<Map> resultList = new ArrayList<Map>();
	
	private NspOnofflogTaImeiDayEntity nspOnofflogTaImeiDayEntity;
	private NspOnofflogTaImeiDayEntityService nspOnofflogTaImeiDayEntityService;
	
	private String selectedId;	
	private String[] selectedIds;	
	private String message;
	
		private String query_logDate;
		private String query_opt;
		private String query_channelno;
		private String query_imeiDayCount;
		private String query_imeiAllCount;
		private String query_imeiNewCount;
		private String query_createUser;
		private String query_createTime;
		private String query_note;
		private String query_id;
		private String query_version;
		private String query_logDate_end;


	public void prepare() {
		super.prepare();
	
		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.nspOnofflogTaImeiDayEntity = nspOnofflogTaImeiDayEntityService.getNspOnofflogTaImeiDayEntity(Long.parseLong(selectedId));
		}
	}
	
	public String queryByPage() {		
		initPageRender();
		
		Map queryMap = new HashMap();	
			    queryMap.put("query_logDate", query_logDate);
				queryMap.put("query_logDate_end", query_logDate_end);
	    	    queryMap.put("query_opt", query_opt);
	    	    queryMap.put("query_channelno", query_channelno);
				queryMap.put("query_version", query_version);


		resultList = nspOnofflogTaImeiDayEntityService.queryNspOnofflogTaImeiDayEntityByPage(queryMap, pageRender);
		
		setPageRenderToRequest();

		return RESULT_QUERY;
	}
	
	public String toAdd() {
		return RESULT_ADD;
	}
	
	public String save() {
	    
		nspOnofflogTaImeiDayEntityService.saveNspOnofflogTaImeiDayEntity(nspOnofflogTaImeiDayEntity);		
		
		message = "新增成功!";
		return RESULT_ADD;
	}
	
	public void validateSave() {
	    	    	    if (nspOnofflogTaImeiDayEntity.getLogDate().length() == 0) {
			this.addActionError("** LogDate 不能为空 !");
		}
			    	    	    if (nspOnofflogTaImeiDayEntity.getOpt().length() == 0) {
			this.addActionError("** Opt 不能为空 !");
		}
			    	    	    if (nspOnofflogTaImeiDayEntity.getChannelno().length() == 0) {
			this.addActionError("** Channelno 不能为空 !");
		}
			    	    	    	    	    	    	    	    	    if (nspOnofflogTaImeiDayEntity.getCreateUser().length() == 0) {
			this.addActionError("** CreateUser 不能为空 !");
		}
			    	    	    	    	    if (nspOnofflogTaImeiDayEntity.getNote().length() == 0) {
			this.addActionError("** Note 不能为空 !");
		}
			    	    	    	    	    if (nspOnofflogTaImeiDayEntity.getVersion().length() == 0) {
			this.addActionError("** Version 不能为空 !");
		}
			    	    
		this.setValidatorResult("/bigdate/NspOnofflogTaImeiDayEntityAdd.jsp");		
	}
	
	public String toEdit() {
	    Long id = new Long(selectedId);
	    
	    nspOnofflogTaImeiDayEntity = nspOnofflogTaImeiDayEntityService.getNspOnofflogTaImeiDayEntity(id);
	
		return RESULT_EDIT;
	}
	
	public String update() {
	
	    nspOnofflogTaImeiDayEntityService.updateNspOnofflogTaImeiDayEntity(nspOnofflogTaImeiDayEntity);	

		message = "修改成功 !";
	    
		return RESULT_EDIT;
	}
	
	public void validateUpdate() {
					    if (nspOnofflogTaImeiDayEntity.getLogDate().length() == 0) {
			this.addActionError("** LogDate不能为空  !");
		}
			    			    if (nspOnofflogTaImeiDayEntity.getOpt().length() == 0) {
			this.addActionError("** Opt 不能为空 !");
		}
			    			    if (nspOnofflogTaImeiDayEntity.getChannelno().length() == 0) {
			this.addActionError("** Channelno 不能为空 !");
		}
			    			    			    			    			    if (nspOnofflogTaImeiDayEntity.getCreateUser().length() == 0) {
			this.addActionError("** CreateUser 不能为空 !");
		}
			    			    			    if (nspOnofflogTaImeiDayEntity.getNote().length() == 0) {
			this.addActionError("** Note 不能为空 !");
		}
			    			    			    if (nspOnofflogTaImeiDayEntity.getVersion().length() == 0) {
			this.addActionError("** Version 不能为空 !");
		}
			    		this.setValidatorResult("/bigdate/NspOnofflogTaImeiDayEntityUpdate.jsp");	
	}
	
	public String delete() {	    
	    List ids = new ArrayList();
	    
		for(String id : selectedIds){
			ids.add(Long.valueOf(id));
		}
		
		try {
			this.nspOnofflogTaImeiDayEntityService.delete(ids);
		} catch (Exception e) {
			System.out.println("异常....");
			this.addActionError("** 可能含有子记录约束冲突,删除失败 !");
		}
		
		
		return queryByPage();
	}

	/**
	 * 导出excel
	 * */
	public void exportExcel(){
		Map queryMap = new HashMap();
		queryMap.put("query_logDate", query_logDate);
		queryMap.put("query_logDate_end", query_logDate_end);
		queryMap.put("query_opt", query_opt);
		queryMap.put("query_channelno", query_channelno);
		queryMap.put("query_version", query_version);

		List<Map> excelList = nspOnofflogTaImeiDayEntityService.queryAllNspOnofflogTaImeiDayEntity(queryMap);

		LinkedHashMap<String, String> namemap = new LinkedHashMap<String, String>();

		//给出中文名称,注：此key要和数据库column一样，否则无法导出
		namemap.put("LOG_DATE", "日期");
		namemap.put("OPT", "运营商");
		namemap.put("VERSION", "运营商");
		namemap.put("CHANNELNO", "渠道号");
		namemap.put("CHANNEL_NO_NAME", "渠道名称");
		namemap.put("IMEI_DAY_COUNT", "IMEI当日数");
		namemap.put("IMEI_ALL_COUNT", "IMEI累计数");
		namemap.put("IMEI_NEW_COUNT", "IMEI新增数");
		Excelexport.exportExcel(excelList, this.getClass().getName(), namemap);
	}


	/**
	 * getters and setters
	 * 
	 * @return
	 */
	 public void setNspOnofflogTaImeiDayEntity(NspOnofflogTaImeiDayEntity nspOnofflogTaImeiDayEntity) {
		this.nspOnofflogTaImeiDayEntity = nspOnofflogTaImeiDayEntity;
	}
	
	public NspOnofflogTaImeiDayEntity getNspOnofflogTaImeiDayEntity() {
		return nspOnofflogTaImeiDayEntity;
	}
	 
	 
	 public void setNspOnofflogTaImeiDayEntityService(NspOnofflogTaImeiDayEntityService nspOnofflogTaImeiDayEntityService) {
		this.nspOnofflogTaImeiDayEntityService = nspOnofflogTaImeiDayEntityService;
	}
	
	public List<NspOnofflogTaImeiDayEntity> getNspOnofflogTaImeiDayEntityList() {
		return nspOnofflogTaImeiDayEntityList;
	}

	public void setNspOnofflogTaImeiDayEntityList(List<NspOnofflogTaImeiDayEntity> nspOnofflogTaImeiDayEntityList) {
		this.nspOnofflogTaImeiDayEntityList = nspOnofflogTaImeiDayEntityList;
	}
	
	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String[] getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String[] selectedIds) {
		this.selectedIds = selectedIds;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}
	
	    public String getQuery_logDate() {
        return this.query_logDate;
    }
    
    public void setQuery_logDate(String logDate){
        this.query_logDate = logDate;
    }    

        public String getQuery_opt() {
        return this.query_opt;
    }
    
    public void setQuery_opt(String opt){
        this.query_opt = opt;
    }    

        public String getQuery_channelno() {
        return this.query_channelno;
    }
    
    public void setQuery_channelno(String channelno){
        this.query_channelno = channelno;
    }    

        public String getQuery_imeiDayCount() {
        return this.query_imeiDayCount;
    }
    
    public void setQuery_imeiDayCount(String imeiDayCount){
        this.query_imeiDayCount = imeiDayCount;
    }    

        public String getQuery_imeiAllCount() {
        return this.query_imeiAllCount;
    }
    
    public void setQuery_imeiAllCount(String imeiAllCount){
        this.query_imeiAllCount = imeiAllCount;
    }    

        public String getQuery_imeiNewCount() {
        return this.query_imeiNewCount;
    }
    
    public void setQuery_imeiNewCount(String imeiNewCount){
        this.query_imeiNewCount = imeiNewCount;
    }    

        public String getQuery_createUser() {
        return this.query_createUser;
    }
    
    public void setQuery_createUser(String createUser){
        this.query_createUser = createUser;
    }    

        public String getQuery_createTime() {
        return this.query_createTime;
    }
    
    public void setQuery_createTime(String createTime){
        this.query_createTime = createTime;
    }    

        public String getQuery_note() {
        return this.query_note;
    }
    
    public void setQuery_note(String note){
        this.query_note = note;
    }

	public void setQuery_id(String id){
		this.query_id = id;
	}

	public String getQuery_version() {
		return this.query_version;
	}

	public void setQuery_version(String version){
		this.query_version = version;
	}


	public String getQuery_logDate_end() {
		return query_logDate_end;
	}

	public void setQuery_logDate_end(String query_logDate_end) {
		this.query_logDate_end = query_logDate_end;
	}
}
